<?php

namespace app\store\controller;

use app\store\model\Store as StoreModel;

/**
 * 后台首页
 * Class Index
 * @package app\store\controller
 */
class Index extends Controller
{
    /**
     * 后台首页
     * @return mixed
     * @throws \think\Exception
     * @throws \think\exception\DbException
     */
    public function index()
    {
        // 当前用户菜单url
        $menus = $this->menus();
        $url = current(array_values($menus))['index'];
        if ($url !== 'index/index') {
            $this->redirect($url);
        }
        if (isset($this->store['user']['store_user_id']) && $this->store['user']['store_user_id']==10004) { //测试数据，后续可删除
            $res = [
                'widget-card' => [
                    'goods_total' => 103, //商品总量
                    'user_total' => 20, //用户总量
                    'order_total' => 21, //订单总量
                    'comment_total' => 22, //评价总量
                ],
                'widget-outline' => [
                    'order_total_price' => [
                        'tday' => '11.00', //销售额(元)
                        'ytd' => '12.00', //昨日销售额(元)
                        //'order_total' => '13.00', //新增用户数
                    ],
                    'order_total' => [
                        'tday' => 1, //支付订单数
                        'ytd' => 2, //昨日支付订单数
                    ],
                    'new_user_total' => [
                        'tday' => 3, //新增用户数
                        'ytd' => 4, //昨日新增用户数
                    ],
                    'order_user_total' => [
                        'tday' => 5, //下单用户数
                        'ytd' => 6, //昨日下单用户数
                    ],
                ],
                'widget-echarts' => [ //近七日交易走势
                    'date' => '["2024-12-21","2024-12-22","2024-12-23","2024-12-24","2024-12-25","2024-12-26","2024-12-27"]',
                    'order_total' => '["1","2","3","4","5","75","6"]',
                    'order_total_price' => '["1.00","2.00","3.00","4.00","5.00","6.00","7.00"]',
                ],
            ];
            return $this->fetch('index', ['data' => $res]);
        }
        $model = new StoreModel;
        return $this->fetch('index', ['data' => $model->getHomeData()]);
    }

}
